import Queue from "./Queue";


class QueueElement {
    constructor(element, priority){
        this.element = element;
        this.priority = priority;
    }
}

export default class PriorityQueue extends Queue {
    constructor() {
        this.items = [];
    }

    insert(element, priority) {
        let qe = new QueueElement(element,priority)
       if(this.items.length === 0){
           this.items.push(qe);
       } else {
           let added = false;
           for(let i=0; i<this.items.length; i++){
               if(qe.priority<this.items[i].priority){
                   this.items.splice(i,0,qe)
                   added = true;
                   break;
               }
           }
           if (!added) {
               this.items.push(qe)
           }
       }
    }

}

